<?php
// constants.php
require_once('General/Util.php');
date_default_timezone_set("America/Los_Angeles");

define("TRIAL_PERIOD", 30);
define("DESCRIBE_KEY", "GLOBAL_DESCRIBE"); // the key for the $_session object that stores describe info
$session_host = '';
$env = array();

// SALESFORCE
define("CP_ORG_USERNAME", "apionly@cirruspath.com");
define("CP_ORG_PASSWORD", 'lemuR64clEft!');
define("CP_ORG_SECTOKEN", 'DENsBvurWNhS9ctP3UdGk3Pz');

$env = json_decode(file_get_contents("/home/dotcloud/environment.json"), true);

// DATABASE
define("REDIS_HOST", $env["DOTCLOUD_REDIS_REDIS_HOST"]);
define("REDIS_PORT", $env["DOTCLOUD_REDIS_REDIS_PORT"]);
define("REDIS_PASS", $env["DOTCLOUD_REDIS_REDIS_PASSWORD"]);
	
define("FE_INSTANCE", $env["DOTCLOUD_SERVICE_ID"]);
define("LOG_FILE", dirname(__FILE__)."/debug.log");

$project_config = array(
	"cirrusinsight" => array(
		"test" => false,
		"webhost" => "https://secure.cirrusinsight.com/",
		"SFDC_OAUTH_CLIENT_ID" => "3MVG9yZ.WNe6byQDEZA1rEr3cCkChbZAC4k8kSkCPDfjxrwxMZLfJxj7bs_P6KGoblM6MLGSapaO6KVYlXoPT",
		"SFDC_OAUTH_SECRET" => "2468778671956153516",
		"SESSION_HOST" => '.cirrusinsight.com',
		// google
		"GOOG_THREE_LEGGED_CONSUMER_KEY" => 'plevirtualbox.servebeer.com',
		"GOOG_THREE_LEGGED_SIGNATURE_METHOD" => 'HMAC-SHA1',
		"GOOG_THREE_LEGGED_CONSUMER_SECRET_HMAC" => 'K0YEfxSzp12gBfM5iF7_BwSB'
	),
	"redistest" => array(
		"test" => true,
		"webhost" => "https://redistest-cirruspath.dotcloud.com/",
		"SFDC_OAUTH_CLIENT_ID" => "3MVG9yZ.WNe6byQDEZA1rEr3cCo1XWIDvVTSyYBbzg1tYb1WxzO80R59Q60.dXCvfF1M0ccTZrzLsFElnxNCh",
		"SFDC_OAUTH_SECRET" => "6941642919700565602",
		"SESSION_HOST" => '.dotcloud.com',
		// google
		"GOOG_THREE_LEGGED_CONSUMER_KEY" => 'plevirtualbox.servebeer.com',
		"GOOG_THREE_LEGGED_SIGNATURE_METHOD" => 'HMAC-SHA1',
		"GOOG_THREE_LEGGED_CONSUMER_SECRET_HMAC" => 'K0YEfxSzp12gBfM5iF7_BwSB'
	),
	"cstmobj" => array(
		"test" => true,
		"webhost" => "https://cstmobj-cirruspath.dotcloud.com/",
		"SFDC_OAUTH_CLIENT_ID" => "3MVG9yZ.WNe6byQDEZA1rEr3cCtDS7caoFwYPa46AnTe7bUPNBDPvI45LZxpwOZ_n7LO5159T5Lw5AXb7wVFc",
		"SFDC_OAUTH_SECRET" => "7243446142754920015",
		"SESSION_HOST" => '.dotcloud.com',
		// google
		"GOOG_THREE_LEGGED_CONSUMER_KEY" => 'plevirtualbox.servebeer.com',
		"GOOG_THREE_LEGGED_SIGNATURE_METHOD" => 'HMAC-SHA1',
		"GOOG_THREE_LEGGED_CONSUMER_SECRET_HMAC" => 'K0YEfxSzp12gBfM5iF7_BwSB'
	),
        "calender" => array(
		"test" => true,
		"webhost" => "https://calender-mubashar.dotcloud.com/",
		"SFDC_OAUTH_CLIENT_ID" => "3MVG9rFJvQRVOvk43P2T87EaAleO_HScYoS2ANPUX2muEWN5Bxg8JcM8dNeDcOtnh1EjaSsiiTMHJG1Zkw3bW",
		"SFDC_OAUTH_SECRET" => "2864065452113985955",
		"SESSION_HOST" => '.dotcloud.com'
	),
        "calendarsync" => array(
		"test" => true,
		"webhost" => "https://calendarsync1-mustafaturabali.dotcloud.com/",
		"SFDC_OAUTH_CLIENT_ID" => "3MVG9Y6d_Btp4xp53Y0e6XEWvcLH4XVxrT.QF1BA_G_.UuXXHK3qag0wGg95lR5TGVqVyRJd2PBKl7liqztiO",
		"SFDC_OAUTH_SECRET" => "1606049670283175510",
		"SESSION_HOST" => '.dotcloud.com'
	)
);

$webhost = null;
$config = $project_config[$env["DOTCLOUD_PROJECT"]];
define("INSIGHT_TEST", $config["test"]);
$webhost = $config["webhost"];

define("SFDC_OAUTH_CLIENT_ID", $config["SFDC_OAUTH_CLIENT_ID"]);
define("SFDC_OAUTH_SECRET", $config["SFDC_OAUTH_SECRET"]);
define("SESSION_HOST", $config["SESSION_HOST"]);
define("SFDC_OAUTH_REDIRECT_URI", $webhost.'sfdcLogin.php');

//define("GOOG_THREE_LEGGED_CONSUMER_KEY", $config["GOOG_THREE_LEGGED_CONSUMER_KEY"]);
//define("GOOG_THREE_LEGGED_SIGNATURE_METHOD", $config["GOOG_THREE_LEGGED_SIGNATURE_METHOD"]);
//define("GOOG_THREE_LEGGED_CONSUMER_SECRET_HMAC", $config["GOOG_THREE_LEGGED_CONSUMER_SECRET_HMAC"]);
//define("GOOG_OAUTH_REDIRECT_URI", $webhost.'googleLogin.php');

session_set_cookie_params(
	$lifetime=0, // for duration of browser session
	'/', // path
	SESSION_HOST, // valid for 'secure.cirrusinsight.com' and 'cirrusinsight.com'
	true, // secure only
	true // http only (cannot be retrieved by javascript)
);
session_start();

define("CURRENT_VERSION", $env["VERSION"]);
// Initiate a new session if they haven't since the newest version was released
if (!array_key_exists("ci_version", $_SESSION) || $_SESSION["ci_version"] != CURRENT_VERSION) {
	Util::logout(); // keeps the SSO token
	
	session_start();
	$_SESSION["ci_version"] = CURRENT_VERSION;
}

define("SFDC_CLIENT_ID", "Cirruspath/Insight/");

define("CRYPT_IV", substr(SFDC_OAUTH_SECRET, 0, 16));
define("API_VERSION", '24.0');

// SALESFORCE OAUTH
if (array_key_exists("custom_login_url", $_COOKIE) && isset($_COOKIE["custom_login_url"])) {
	// If they use My Domain or SSO, they'll hit a different URL
	define("SALESFORCE_HOST", urldecode($_COOKIE["custom_login_url"]));
} else {
	define("SALESFORCE_HOST", "https://login.salesforce.com/");
}

$oauth_token_scope = "full%20refresh_token";
//$oauth_token_scope = "refresh_token";
define('SFDC_AUTH_CODE_URL', SALESFORCE_HOST . 'services/oauth2/authorize?response_type=code&client_id='.SFDC_OAUTH_CLIENT_ID.'&redirect_uri=' . urlencode(SFDC_OAUTH_REDIRECT_URI) . '&display=popup&scope='.$oauth_token_scope.'&code=');
define('SFDC_ACCESS_TOKEN_URL', SALESFORCE_HOST . 'services/oauth2/token?grant_type=authorization_code&client_id='.SFDC_OAUTH_CLIENT_ID.'&client_secret='.SFDC_OAUTH_SECRET.'&redirect_uri='.urlencode(SFDC_OAUTH_REDIRECT_URI).'&code=');
define('SFDC_REFRESH_TOKEN_URL', SALESFORCE_HOST . 'services/oauth2/token?grant_type=refresh_token&client_id='.SFDC_OAUTH_CLIENT_ID.'&client_secret='.SFDC_OAUTH_SECRET.'&refresh_token=');

// PHP TOOLKIT
define("PARTNER_WSDL", dirname(__FILE__).'/SalesforceApi/soapclient/partner.wsdl.xml');

// ORDERING
define("ITEM_CODE", "CI_STANDARD");
define("PRICE_BOOK", "a0B3000000DD5WoEAL"); // PRODUCTION
	
?>